package com.sc.everyonerentboot.controller;

import com.sc.everyonerentboot.pojo.Products;
import com.sc.everyonerentboot.pojo.Result;
import com.sc.everyonerentboot.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/product")
public class ProductsController {
    @Autowired
    ProductService ps;
    @RequestMapping("/add")
    public Result add(@RequestBody Products p){
        int i=ps.add(p);
        if (i>0){
            return new Result(1,"添加成功");
        }
        return  new Result(0,"添加失败");
    }
    @RequestMapping("/del")
    public Result del(Integer id){
        int i=ps.del(id);
        if (i>0){
            return new Result(1,"删除成功");
        }
        return  new Result(0,"删除失败");
    }

    @RequestMapping("/update")
    public Result update(@RequestBody Products p){
        int i=ps.update(p);
        if (i>0){
            return new Result(1,"修改成功");
        }
        return  new Result(0,"修改失败");
    }
    @RequestMapping("/showAll")
    public Result showById(@RequestParam(defaultValue = "1") Integer pageNum,
                           @RequestParam(defaultValue = "5") Integer pageSize,
                           Products p
                           ){
        return new Result(1,"查询成功",ps.showAll(pageNum,pageSize,p));
    }
}
